package com.parenting.controller;


import com.parenting.model.IMPage;
import com.parenting.model.UserDTO;
import com.parenting.oauth2.config.AuthUtil;
import com.parenting.request.AddGiftRequest;
import com.parenting.request.SearchGiftPageListRequest;
import com.parenting.request.UpdateGiftRequest;
import com.parenting.response.GiftPageListResponse;
import com.parenting.response.GiftResponse;
import com.parenting.service.GiftService;
import com.parenting.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 连带赠表 前端控制器
 * </p>
 *
 * @author 烟台业达-王世玺
 * @since 2021-09-15
 */
@RestController
@RequestMapping("/gift")
@Api(tags = "活动管理-连带增管理", description = "连带增的增删改查")
public class GiftController {
    @Autowired
    private GiftService giftService;

    /***
     * 连带增活动新增
     * @param request
     */
    @ApiOperation("新增优惠券")
    @PostMapping
    public Result saveGift(@RequestBody @Validated  AddGiftRequest request){
        giftService.saveGift(request, AuthUtil.getUserInfo());
       return Result.success();
    }

    /***
     * 分页
     * @param request
     * @return
     */
    @ApiOperation("连带增列表")
    @PostMapping("search")
    public Result<IMPage<GiftPageListResponse>> pageListGift(@RequestBody SearchGiftPageListRequest request){
        request.setShopId(AuthUtil.getUserInfo().getShopId());
        return Result.buildSuccess(giftService.pageListGift(request));
    }


    /***
     * 详情
     * @param id
     * @return
     */
    @ApiOperation("连带增详情表")
    @ApiImplicitParam(name = "id", value = "就是 activityId", required = true)
    @GetMapping("{id}")
    public Result<GiftResponse> getGiftResponseById(@PathVariable("id") String id){

        return Result.buildSuccess(giftService.getGiftResponseById(id));
    }


    /***
     * 修改 连带增活动 优惠券数量
     * @param request
     */
    @ApiOperation("修改连带增数据")
    @PutMapping
    public Result  updateGift(@RequestBody UpdateGiftRequest request){
        giftService.updateGift(request);
        return Result.buildSuccess();
    }

}

